//
//  HWDateCell.m
//  HuaWan
//
//  Created by HuaWan on 2022.
//  Copyright © 2022年 HuaWan. All rights reserved.
//

#import "HWDateCell.h"

@implementation HWDateCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setData:(id)data delegate:(id)delegate {
    _delegate = delegate;
    if ([data isKindOfClass:[NSDictionary class]]) {
        if ([data[@"data"] isKindOfClass:[HWDateCellModel class]]) {
            HWDateCellModel *model = data[@"data"];
            //用于格式化NSDate对象
            NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
            [formatter setDateFormat:@"yyyy-MM"];
            NSDate *d = [formatter dateFromString:model.month];
            [formatter setDateFormat:@"yyyy"];
            _yearLabel.text = [NSString stringWithFormat:@"%@年",[formatter stringFromDate:d]];
            [formatter setDateFormat:@"MM"];
            _monthLabel.text = [NSString stringWithFormat:@"%@月",[formatter stringFromDate:d]];
        }
    }
}

- (IBAction)buttonAction:(UIButton *)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(dateCell:button:)]) {
        [_delegate dateCell:self button:sender];
    }
}

@end

#pragma mark - Model

@implementation HWDateCellModel

+ (HWDateCellModel *)ittemModelWithMonth:(NSString *)month {
    HWDateCellModel *model = [HWDateCellModel new];
    model.month = kSafeString(month);
    return model;
}

@end
